using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using CHARACTERS;

namespace TEST
{
    public class Test_Character : MonoBehaviour
    {
        // Start is called before the first frame update
        void Start()
        {
            //Character raelin = CharacterManager.instance.CreateCharacter("Raelin");
            StartCoroutine(Test7());
        }

        IEnumerator Test7()
        {
            SpritCharacter Raelin = CharacterManager.instance.CreateCharacter("Raelin") as SpritCharacter;
            SpritCharacter Guard1 = CharacterManager.instance.CreateCharacter("Guard1 @ Generic") as SpritCharacter;
            Raelin.Show();
            Guard1.Show();
            Raelin.SetPosition(new Vector2(0, 0));
            Guard1.SetPosition(new Vector2(1, 0));
            yield return new WaitForSeconds(1f);

            Raelin.FaceRight();
            Guard1.FaceRight();
            yield return new WaitForSeconds(1f);
            Raelin.FaceLeft();
            Guard1.FaceLeft();
        }

        IEnumerator Test6()
        {
            yield return new WaitForSeconds(2);
            SpritCharacter fs2 = CharacterManager.instance.CreateCharacter("Female student 2") as SpritCharacter;
            SpritCharacter ra = CharacterManager.instance.CreateCharacter("Raelin") as SpritCharacter;

            Debug.Log($"ra visible:{ra.isVisible}");
            ra.Appear();
            Debug.Log($"ra visible:{ra.isVisible}");
            ra.Hide();
            Debug.Log($"ra visible:{ra.isVisible}");
            ra.Show();
            Debug.Log($"ra visible:{ra.isVisible}");
            ra.Cover();
            Debug.Log($"ra visible:{ra.isVisible}");
        }

        IEnumerator Test5()
        {
            yield return new WaitForSeconds(2);
            SpritCharacter fs2 = CharacterManager.instance.CreateCharacter("Female student 2") as SpritCharacter;
            SpritCharacter ra = CharacterManager.instance.CreateCharacter("Raelin") as SpritCharacter;
            Debug.Log("1");
            fs2.SetPosition(Vector2.zero);
            ra.SetPosition(new Vector2(1f,0f));
            yield return fs2.Appear();
            yield return ra.Appear();

            fs2.Animate("Hop");
            yield return fs2.Say("Hey you!");
            ra.Animate("Shiver",true);
            yield return ra.Say("Why she found me");
            ra.Animate("Shiver",false);
            yield return fs2.Say("Stop!");

        }

        IEnumerator Test4()
        {
            yield return new WaitForSeconds(2);

            SpritCharacter fs2 = CharacterManager.instance.CreateCharacter("Female student 2") as SpritCharacter;
            SpritCharacter ra = CharacterManager.instance.CreateCharacter("Raelin") as SpritCharacter;
            fs2.SetPosition(Vector2.zero);
            ra.SetPosition(Vector2.zero);
            SpritCharacter g1 = CharacterManager.instance.CreateCharacter("g1 @ Generic") as SpritCharacter;
            g1.SetPosition(Vector2.zero);
            yield return g1.Appear();

            yield return fs2.Appear();
            yield return ra.Appear();
            yield return ra.Say("ready to flip");

            fs2.SetPriority(5);
            ra.SetPriority(3);
            g1.SetPriority(1000);
            yield return ra.Flip(0.3f);
            yield return ra.Say("ready to flip");
            CharacterManager.instance.SortCharacters(new string[] { "Raelin", "g1" });
            //        fs2.facingLeft = false;
            yield return fs2.Flip(0.3f);

            yield return ra.Say("ready to flip immediate");
            CharacterManager.instance.SortCharacters(new string[] { "Raelin", "g1" , "Female student 2" });
            yield return ra.Flip(immediate:true);

            //        fs2.facingLeft = false;
            yield return fs2.Flip(immediate: true);


            yield return new WaitForSeconds(1);
            yield return ra.Unhighlight();

            yield return new WaitForSeconds(1);
            yield return ra.TransitionColor(Color.red);
            yield return new WaitForSeconds(1);
            yield return ra.Highlight();
            yield return new WaitForSeconds(1);
            yield return ra.TransitionColor(Color.white);
            yield return new WaitForSeconds(1);
            yield return ra.Unhighlight();
            yield return null;
        }
        IEnumerator Test3()
        {
            yield return new WaitForSeconds(2);

/*            SpritCharacter fs2 = CharacterManager.instance.CreateCharacter("Female student 2") as SpritCharacter;
            fs2.SetPosition(new Vector2(0.5f, 0.5f));
            yield return fs2.Appear();
            yield return new WaitForSeconds(2);
            fs2.SetSprite(fs2.GetSprite("smile"));
            yield return fs2.Say("smile");

            yield return new WaitForSeconds(2);
            fs2.SetSprite(fs2.GetSprite("sad"));
            yield return fs2.Say("sad");
            yield return null;
            yield return fs2.Hide();

            SpritCharacter g1 = CharacterManager.instance.CreateCharacter("g1 @ Generic") as SpritCharacter;
            g1.SetPosition(Vector2.one);
            yield return g1.Appear();
            yield return new WaitForSeconds(2);
            g1.SetSprite(g1.GetSprite("Monk"));
            yield return g1.Say("Monk");
            yield return g1.Hide();*/

            SpritCharacter ra = CharacterManager.instance.CreateCharacter("Raelin") as SpritCharacter;
            ra.SetPosition(Vector2.zero);
            yield return ra.Appear();
            yield return ra.Say("change face and body");

            yield return ra.TransitionColor(Color.red,0.3f);
            yield return ra.TransitionColor(Color.blue);
            yield return ra.TransitionColor(Color.yellow);
            yield return ra.TransitionColor(Color.white);

            yield return ra.Say("change color");
            yield return ra.Hide();
        }

        IEnumerator Test2()
        {
            Character g1 = CharacterManager.instance.CreateCharacter("g1 @ Generic");
            Debug.Log("g1 appear");
            yield return g1.Appear();
            Debug.Log("g1 Hide");
            yield return g1.Hide();
            g1.SetPosition(Vector2.zero);
            g1.Say("Hi");
            Debug.Log("g1 appear");
            yield return g1.Appear();
            Debug.Log("g1 Hide");
            yield return g1.Hide();
            g1.SetPosition(Vector2.one);
            Debug.Log("g1 appear");
            yield return g1.Appear();
            //Debug.Log("g1 Hide");
            //yield return g1.Hide();
            Character fs2 = CharacterManager.instance.CreateCharacter("Female student 2");
            Debug.Log("fs2 appear");
            fs2.Say("Hi");
            yield return fs2.Appear();
        }

        IEnumerator Test()
        {
            Character femaleStudent = CharacterManager.instance.CreateCharacter("Female student 2");
            
            femaleStudent.SetPosition(new Vector2(0.5f, 0.5f));
            
            femaleStudent.Appear();
            
            yield return femaleStudent.MoveToPosition(new Vector2(1, 1));
            femaleStudent.MoveToPosition(new Vector2(0, 0));
            yield return femaleStudent.Say("hi~");

            Character g1 = CharacterManager.instance.CreateCharacter("g1 @ Generic");
            

            g1.SetPosition(Vector2.zero);
            g1.Appear();
            yield return g1.MoveToPosition(new Vector2(1, 1));
            g1.MoveToPosition(new Vector2(0, 0));
            yield return g1.Say("hi~");

            Character realin = CharacterManager.instance.CreateCharacter("Raelin");
            realin.Appear();
            yield return realin.MoveToPosition(new Vector2(1, 1));
            realin.MoveToPosition(new Vector2(0, 0));
            yield return realin.Say("hi~");
        }
        // Update is called once per frame
        void Update()
        {

        }
    }
}